package com.foreknow.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;

public class GetValueAction extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	PrintWriter out = resp.getWriter();
	//获取请求参数
	String action = req.getParameter("action");
	if(action.equals("getvalue")) {
		String[] str = getValue();
		//利用jsonlib将数据转换为json串返回给前台
		JSONArray jArray = JSONArray.fromObject(str);
		out.println(jArray.toString());
	}
}

public String[] getValue() {
	String[] str = new String[4];
	str[0] = "java";
	str[1] = "nodejs";
	str[2] = "angularjs";
	str[3] = "bootstrap";
	return str;
}

@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
